<?php

$this->title = '总体核账';
use yii\helpers\Html;
use kartik\widgets\DatePicker;
use backend\modules\statistics\assets\EchartsAsset;
EchartsAsset::register($this);

?>



<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
              <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">
                <div class="business-pig-index">
                    <form action="">
                    <div class="row">
                        <div class="col-md-3 col-md-offset-1">
                            <?php
                                echo Html::label('起始日期');
                                echo DatePicker::widget([
                                'name' => 'start_date',
                                'value' => date('Y-m-d', strtotime('-30 days')),
                                'options' => ['placeholder' => '选择核账的起始日期'],
                                'pluginOptions' => [
                                    'format' => 'yyyy-mm-dd',
                                    'todayHighlight' => true,
                                    'autoclose'=>true,
                                ]
                            ]);
                            ?>
                        </div>
                        <div class="col-md-3 col-md-offset-1">
                            <?php
                                echo Html::label('结束日期');
                                echo DatePicker::widget([
                                    'name' => 'end_date',
                                    'value' => date('Y-m-d'),
                                    'options' => ['placeholder' => '选择核账的结束日期'],
                                    'pluginOptions' => [
                                        'format' => 'yyyy-mm-dd',
                                        'todayHighlight' => true,
                                        'autoclose'=>true,
                                    ]
                                ]);
                            ?>
                        </div>

                        <div class="col-md-2 col-md-offset-1">
                            <?=
                                Html::submitButton('核账',['class'=>'btn btn-primary','style'=>'margin-top:20px;']);
                            ?>
                        </div>
                    </div>
                    </form>

                    <div class="row" style="margin-top: 40px;">
                        <div class="col-md-10 col-md-offset-1">
                            <h2>已收</h2>
                            <table class="table">
                                <tr>
                                    <th>认养费</th>
                                    <th>宰杀</th>
                                    <th>线上销售</th>
                                    <th>线下大客户销售</th>
                                    <th>农家乐收入</th>
                                    <th>总计</th>
                                </tr>
                                <tr>
                                    <td><?= $get['rasprice'] ?></td>
                                    <td><?= $get['killprice'] ?></td>
                                    <td><?= $get['goodsprice'] ?></td>
                                    <td><?= $get['customerprice'] ?></td>
                                    <td><?= $get['houseprice'] ?></td>
                                    <td><?= $get['total'] ?></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-10 col-md-offset-1">
                            <h2>已付</h2>
                            <table class="table">
                                <tr>
                                    <th>购买仔猪费</th>
                                    <?php foreach ($pay['pigcost'] as $key => $row) { ?>
                                        <th><?=$key?></th>
                                    <?php } ?>
                                    <?php foreach ($pay['personcost'] as $key => $row) { ?>
                                        <th><?=$key?></th>
                                    <?php } ?>
                                    <th>总计</th>
                                </tr>
                                <tr>
                                    <td><?= $pay['pig'] ?></td>
                                    <?php foreach ($pay['pigcost'] as $key => $row) { ?>
                                        <td><?=$row['sumprice']?></td>
                                    <?php } ?>
                                    <?php foreach ($pay['personcost'] as $key => $row) { ?>
                                        <td><?=$row['sumprice']?></td>
                                    <?php } ?>
                                    <td><?=$pay['total']?></td>
                                </tr>
                            </table>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-10 col-md-offset-1">
                            <h2>毛利</h2>
                            已收（<?= $get['total'] ?>）-已付（<?=$pay['total']?>） = <?= $get['total']-$pay['total']?>
                        </div>
                    </div>

                    <div class="row" style="margin-top: 40px;">
                        <div class="col-md-10 col-md-offset-1">
                           <div id="finance" style="width: 100%;height: 400px;"></div>
                        </div>
                    </div>
            </div>
        </div>
    </section>
</section>
<script>
    <?php $this->beginBlock('js_end') ?>


        option = {
            title : {
                text: '统计报表',
                subtext: '',
                x:'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b}: {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                x: 'left',
//                data:['直达','营销广告','搜索引擎','邮件营销','联盟广告','视频广告','百度','谷歌','必应','其他']
                data:<?=$names?>
            },
            series: [
                {
                    name:'访问来源',
                    type:'pie',
                    selectedMode: 'single',
                    radius: [0, '30%'],

                    label: {
                        normal: {
                            position: 'inner'
                        }
                    },
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },
                    data : <?= $gets ?>
//                    data:[
//                        {value:335, name:'直达', selected:true},
//                        {value:679, name:'营销广告'},
//                        {value:1548, name:'搜索引擎'}
//                    ]
                },
                {
                    name:'访问来源',
                    type:'pie',
                    radius: ['40%', '55%'],
                    data:<?= $pays ?>

//                    data:[
//                        {value:335, name:'直达'},
//                        {value:310, name:'邮件营销'},
//                        {value:234, name:'联盟广告'},
//                        {value:135, name:'视频广告'},
//                        {value:1048, name:'百度'},
//                        {value:251, name:'谷歌'},
//                        {value:147, name:'必应'},
//                        {value:102, name:'其他'}
//                    ]
                }
            ]
        };

    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('finance'));
    myChart.setOption(option);

    <?php $this->endBlock(); ?>
    <?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
</script>
